/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Database.OraConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Prasetyawan
 */
public class BarangPesan {
    private String kodeToko;
    private String namaToko;
    private String kodeBarang;
    private String namaBarang;
    private String jenisBarang;
    private int jumlahBarang;
    private int hargaBarang;
    
     private Connection con;
    private Barang barang;

    public BarangPesan() {
        con = OraConnection.getKoneksi();

    }

    

    /**
     * @return the kodeToko
     */
    public String getKodeToko() {
        return kodeToko;
    }

    /**
     * @param kodeToko the kodeToko to set
     */
    public void setKodeToko(String kodeToko) {
        this.kodeToko = kodeToko;
    }

    /**
     * @return the namaToko
     */
    public String getNamaToko() {
        return namaToko;
    }

    /**
     * @param namaToko the namaToko to set
     */
    public void setNamaToko(String namaToko) {
        this.namaToko = namaToko;
    }

    /**
     * @return the kodeBarang
     */
    public String getKodeBarang() {
        return kodeBarang;
    }

    /**
     * @param kodeBarang the kodeBarang to set
     */
    public void setKodeBarang(String kodeBarang) {
        this.kodeBarang = kodeBarang;
    }

    /**
     * @return the namaBarang
     */
    public String getNamaBarang() {
        return namaBarang;
    }

    /**
     * @param namaBarang the namaBarang to set
     */
    public void setNamaBarang(String namaBarang) {
        this.namaBarang = namaBarang;
    }

    /**
     * @return the jenisBarang
     */
    public String getJenisBarang() {
        return jenisBarang;
    }

    /**
     * @param jenisBarang the jenisBarang to set
     */
    public void setJenisBarang(String jenisBarang) {
        this.jenisBarang = jenisBarang;
    }

    /**
     * @return the jumlahBarang
     */
    public int getJumlahBarang() {
        return jumlahBarang;
    }

    /**
     * @param jumlahBarang the jumlahBarang to set
     */
    public void setJumlahBarang(int jumlahBarang) {
        this.jumlahBarang = jumlahBarang;
    }

    /**
     * @return the hargaBarang
     */
    public int getHargaBarang() {
        return hargaBarang;
    }

    /**
     * @param hargaBarang the hargaBarang to set
     */
    public void setHargaBarang(int hargaBarang) {
        this.hargaBarang = hargaBarang;
    }
    
    public void tambahBarang(BarangPesan barang) throws SQLException {
        String nt = barang.getNamaToko();
        String kt = barang.getKodeToko();
        String kb = barang.getKodeBarang();
        String nb = barang.getNamaBarang();
        String jns = barang.getJenisBarang();
        int jml = barang.getJumlahBarang();
        int hrg = barang.getHargaBarang();

        String sql = "insert into daftarpesananbarang (NAMATOKO,KODETOKO,KODEBARANG,NAMABARANG,JENIS,JUMLAH,HARGABARANG)"
                + " values ('" + nt + "','" + kt + "','" + kb + "','" + nb + "','" + jns + "','" + jml + "','" + hrg + "')";
        Statement stat = con.createStatement();
        stat.executeUpdate(sql);
        con.close();
    }
 public List viewdaftarpesanan() {
        List listBarang = new ArrayList();

        try {
            String query = "select * from DAFTARPESANANBARANG";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                BarangPesan barang = new BarangPesan();
                barang.setNamaToko(rs.getString(1));
                barang.setKodeToko(rs.getString(2));
                barang.setKodeBarang(rs.getString(3));
                barang.setNamaBarang(rs.getString(4));
                barang.setJenisBarang(rs.getString(5));
                barang.setJumlahBarang(rs.getInt(6));
                barang.setHargaBarang(rs.getInt(7));
                listBarang.add(barang);
            }
        } catch (Exception e) {
            Logger.getLogger(BarangPesan.class.getName()).log(Level.SEVERE, null, e);
        }
        return listBarang;
    }
}